home *** CD-ROM | disk | FTP | other *** search
- /*
- * extract.c
- *
- * Changes map database from binary to text
- */
-
- #include <stdio.h>
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- FILE *fpi, *fpo;
- struct { int code, lat, lon; } coord;
- int n, degrees, minutes;
- char type[80], tmp[16];
-
- if (argc != 3) {
- printf("Usage: extract input.pnt output.asc\n");
- exit(1);
- }
-
- if ((fpi = fopen(argv[1], "rb")) == (FILE *)NULL) {
- printf("\007Error: Can't locate Database '%s'\n", argv[1]);
- exit(1);
- }
-
- if ((fpo = fopen(argv[2], "w")) == (FILE *)NULL) {
- printf("\007Error: Can't create Database '%s'\n", argv[2]);
- exit(1);
- }
-
- while (fread((char *)&coord, sizeof coord, 1, fpi) > 0) {
- itoa(coord.code, tmp, 10);
- strcpy(type, tmp);
- strcat(type, ", ");
-
- if (coord.lat < 0)
- strcat(type, "-");
-
- minutes = abs(coord.lat) % 60;
- degrees = abs(coord.lat) / 60;
-
- itoa(degrees, tmp, 10);
- strcat(type, tmp);
- strcat(type, ".");
- itoa(minutes, tmp, 10);
-
- if (minutes < 10)
- strcat(type, "0");
-
- strcat(type, tmp);
- strcat(type, ", ");
-
- if (coord.lon < 0)
- strcat(type, "-");
-
- minutes = abs(coord.lon) % 60;
- degrees = abs(coord.lon) / 60;
-
- itoa(degrees, tmp, 10);
- strcat(type, tmp);
- strcat(type, ".");
- itoa(minutes, tmp, 10);
-
- if (minutes < 10)
- strcat(type, "0");
-
- strcat(type, tmp);
- strcat(type, "\n");
-
- fwrite(type, sizeof(char), strlen(type), fpo);
- }
-
- fclose(fpi);
- fclose(fpo);
-
- exit(0);
- }